<?php
/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Game
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */
class Game_Widget_ListScoresController extends Engine_Content_Widget_Abstract
{
  public function indexAction()
  {
    // Don't render this if not authorized
    $viewer = Engine_Api::_()->user()->getViewer();


    $params = array(
      'limit' => $this->_getParam('max', 10),
      'user' => $this->_getParam('user'),
      'game' => $this->_getParam('game'),
      'period' => $this->_getParam('period'),
      'order' => $this->_getParam('order', 'recent'),
    );    
    
    $this->view->paginator = $paginator = Engine_Api::_()->getItemTable('game_score')->getScorePaginator($params);
    
    
    if ($paginator->getTotalItemCount() == 0 && !$this->_getParam('showemptyresult', false)) {
      return $this->setNoRender();
    }    
    
    // speed thing up :-)
    Engine_Api::_()->getItemTable('game_score')->preloadUsers($paginator);
  }
}